﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.intellitack.layar.library
{
    public class LayarResponse : AbstractLayarObject
    {
        #region Protected Properties
        protected string _nextPageKey;
        protected Boolean? _morePages;
        protected List<PointOfInterest> _hotspots;
        protected string _layer;
        protected int? _errorCode;
        protected string _errorString;
        #endregion

        #region Constructors
        public LayarResponse() 
        {
            _hotspots = new List<PointOfInterest>();
            _errorCode = 0;
            _errorString = "ok";
            _morePages = false;
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Optional:  The key to the page being returned.  Pass this key to the page paramter in the request if the next page is requested
        /// </summary>
        public string nextPageKey
        {
            get
            {
                return _nextPageKey;
            }
            set
            {
                _nextPageKey = value;
            }
        }

        /// <summary>
        /// Optional:  Whether more pages can be fetched.
        /// </summary>
        public bool? morePages
        {
            get
            {
                return _morePages;
            }
            set
            {
                _morePages = value;
            }
        }

        /// <summary>
        /// The list of POIs for the current location and layer
        /// </summary>
        public List<PointOfInterest> hotspots
        {
            get
            {
                return _hotspots;
            }
            
        }

        /// <summary>
        /// The name of the layer for which the POI's are returned
        /// </summary>
        public string layer
        {
            get
            {
                return _layer;
            }
            set
            {
                _layer = value;
            }
        }

        /// <summary>
        /// If an error condition occurs, this will be notified using the error code. 
        /// Note that in this case, the server is actually responding, this is different than 
        /// a HTTP 500 Error situation (server error).
        ///   0 = "ok". No error, data available in the other fields.
        /// Use any error code between 20-29 to send back an error. The string of the error will 
        /// be displayed as a message in the screen of the user. Note that this will only be 
        /// displayed if this is the first page in the response, errors sent in any successive page will be ignored.
        /// </summary>
        public int? errorCode
        {
            get
            {
                return _errorCode;
            }
            set
            {
                _errorCode = value;
            }
        }

        /// <summary>
        /// The string for the error above.  Max 80 characters.
        /// </summary>
        public string errorString
        {
            get
            {
                return _errorString;
            }
            set
            {
                _errorString = value;
            }
        }
        #endregion

        public override string Serialize()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("{");
            sb.Append(string.Format("{0},", SerializeProperty("nextPageKey", nextPageKey)));
            sb.Append(string.Format("{0},", SerializeProperty("morePages", morePages)));
            sb.Append(string.Format("{0},", SerializeEnumeration("hotspots", hotspots)));
            sb.Append(string.Format("{0},", SerializeProperty("layer", layer)));
            sb.Append(string.Format("{0},", SerializeProperty("errorCode", errorCode)));
            sb.Append(string.Format("{0}", SerializeProperty("errorString", errorString)));

            sb.Append("}");
            return sb.ToString();
        }
    }
}
